﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataAccess
{
    /// <summary>
    /// Sql语句的结构类．
    /// </summary>

    [Serializable]
    public class SqlStruct
    {
        public SqlStruct(string strSql, ParamField[] paramField)
        {
            if (PersistenceProperty.DatabaseType == DatabaseType.MSSQLServer
                || PersistenceProperty.DatabaseType == DatabaseType.DB2)
            {
                this.m_SqlString = strSql.Replace(":", "@");
                this.m_ParamFields = paramField;
            }
            else
            {
                this.m_SqlString = strSql.Replace("@", ":");
                this.m_ParamFields = paramField;
            }
        }
        public SqlStruct() { }

        private string m_SqlString;  //Sql语句
        public string SqlString
        {
            get { return this.m_SqlString; }
            set
            {
                if (PersistenceProperty.DatabaseType == DatabaseType.MSSQLServer
                    || PersistenceProperty.DatabaseType == DatabaseType.DB2)
                    this.m_SqlString = value.Replace(":", "@");
                else
                    this.m_SqlString = value.Replace("@", ":");

            }

        }

        private ParamField[] m_ParamFields; //参数及相关数据表的Field列表
        public ParamField[] ParamFields
        {
            get { return this.m_ParamFields; }
            set { this.m_ParamFields = value; }
        }
    }

    [Serializable]
    public class ParamField
    {
        public ParamField(string strParamName, string strFieldName)
        {
            if (PersistenceProperty.DatabaseType == DatabaseType.MSSQLServer
                || PersistenceProperty.DatabaseType == DatabaseType.DB2)
            {
                this.m_ParamName = strParamName.Replace(":", "@");
                this.m_FieldName = strFieldName;
            }
            else
            {
                this.m_ParamName = strParamName.Replace("@", ":");
                this.m_FieldName = strFieldName;

            }
        }

        private string m_ParamName;
        public string ParamName
        {
            get { return this.m_ParamName; }
            //set{this.m_ParamName=value;}
        }

        private string m_FieldName;
        public string FieldName
        {
            get { return this.m_FieldName; }
            //set{this.m_FieldName=value;}
        }
    }
}
